home *** CD-ROM | disk | FTP | other *** search
/ Resource for Source: C/C++ / Resource for Source - C-C++.iso / codelib9 / v_11_11 / feeney / timer.c < prev    next >
Encoding:
Text File  |  1995-11-01  |  475 b   |  24 lines

  1.       LISTING 4
  2.     A Basic Timer Function
  3. /*
  4.   Hang until delay has expired.
  5.  
  6.   delay in milliseconds
  7. */
  8. BOOL Sleep( long delay ) {
  9.   long  timer,   // current time
  10.     base,    // starting time
  11.     elapsed; // time spent in loop
  12.  
  13.   if ( !delay ) return(FALSE);
  14.   base = clock();
  15.   if ( base == -1 ) return(FALSE);
  16.   do {
  17.     timer = clock();
  18.     if ( timer == -1L ) return(FALSE);
  19.     elapsed = timer - base;
  20.   } while ( delay > elapsed );
  21.   return(TRUE);
  22. }
  23.  
  24.